/**
 * Created by lizhe on 2018/4/16.
 */
var type = ["","文章","图片","教师","学生","基本概况","教师风采"];
var statu = ["","待审核","审核通过","驳回","草稿"];
var studentPosition = ["请选择","大队委","大队副","大队体育委","大队文娱委","大队宣传委","大队纪律委","大队劳动委","大队组织委","大队卫生委","大队学习委","大队旗手"];
var starList = ["请选择","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天秤座","天蝎座","射手座","摩羯座","水瓶座","双鱼座"];
var ids = [];
var typeName = "";
var croppable = false;
var ZtreeId = 0;
var ZtreeName = "";
var ZtreeType = 0;
var zNodes =[];
var zNodes2 = [];
var datas=[];

var zTreeSelect=[];

var setting = {
    callback: {
        onClick: zTreeOnClick
    },
    data: {
        simpleData: {
            enable: true
        }
    }
};

var selectSetting = {
    callback: {
        onCheck: onCheck
    },
    view: {
        selectedMulti: false
    },
    check: {
        enable: true,
        chkStyle: "checkbox",
        chkboxType: { "Y": "", "N": "" }
    },
    data: {
        simpleData: {
            enable: true
        }
    }
};


//ztree回调
function zTreeOnClick(event, treeId, treeNode) {
    var id = treeNode.id;
    var name = treeNode.name;
    var tId = treeNode.tId;
    ZtreeId = id;
    ZtreeName = name;
    ZtreeType = treeNode.type;
    if(ZtreeType == 6){
        teacherPage(1,15,id);
    }else{
        queryArticle(1,15,id);
    }
}

function onCheck(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj("selectTree");
    var Nodes = zTree.getCheckedNodes(true);
    zTreeSelect = [];
    for(var i = 0;i< Nodes.length;i++){
        //var type =
        var d = {
            id:Nodes[i].id,parendId:Nodes[i].pId,name:Nodes[i].name,type:Nodes[i].type
        };
        zTreeSelect.push(d);
    }
}

$(document).ready(function(){
    var $image = $("#image");
    $image.cropper({
        aspectRatio: 194/124,
        viewMode: 1,
        ready: function () {
            croppable = true;
        }
    });

//日期插件
    $(".form_datetime").datetimepicker({
        format: 'yyyy-mm-dd',//显示格式
        language:  'zh-CN',  //日期,
        todayHighlight: 1,//今天高亮
        minView: "month",//设置只显示到月份
        startView:2,
        forceParse: 0,
        showMeridian: 1,
        autoclose: 1//选择后自动关闭
    });

    //返回
    $(".btn-warning").click(function(){
        $("#toArticle").click();
    });

    //翻页
    $("#page").click(function(){
        var page = $("#page").data('pagination').currentPage + 1;
        if(ZtreeType == 6){
            teacherPage(page,15,ZtreeId);
        }else{
            queryArticle(page,15,ZtreeId);
        }
    });

    //新增
    $("#add_article").click(function(){
        if(ZtreeId==0){
            modalinfo("请选择菜单");
        }else{
            document.getElementById("columnType").innerHTML = "新增";
            document.getElementById("image_type").innerHTML = "add";
            var str = ZtreeName;
            str = str.split("(");
            var str1 = str[1].split(")");
            typeName = str1[0];
            addInit();
            if(typeName == "文章" || typeName == "基本概况"){
                allHide();
                $("#toAdd").click();
                document.getElementById("add_name").innerHTML = "<span class='import'>*</span>标题";
                document.getElementById("add_title").placeholder = "标题";
                if(typeName == "文章"){
                    document.getElementById("add_topTitle").innerHTML = "新增文章";
                }else {
                    document.getElementById("add_topTitle").innerHTML = "新增基本概况";
                }
                document.getElementById("add_imgTitle").innerHTML = "封面图片";
                document.getElementById("add-author").style.display = "";
                document.getElementById("add-source").style.display = "";
                document.getElementById("add-subtitle").style.display = "";
                document.getElementById("add-keywords").style.display = "";
                document.getElementById("add-submitTime").style.display = "";
                document.getElementById("add_contentTitle").style.display = "";
                document.getElementById("edit").style.display = "";

                document.getElementById("uploadImg").setAttribute("class", "uploadImg1");
                document.getElementById("uploadImg").src = "images/articleAdd.png";
                document.getElementById("add_imgUrl").innerHTML = "images/articleAdd.png";
                document.getElementById("add-imgDel").style.marginRight = "56px";
            }else if(typeName == "图片"){
                allHide();
                $("#toAdd").click();
                document.getElementById("add_name").innerHTML = "<span class='import'>*</span>标题";
                document.getElementById("add_title").placeholder = "标题";
                document.getElementById("add_topTitle").innerHTML = "新增图片";
                document.getElementById("add_imgTitle").innerHTML = "<span class='import'>*</span>封面图片";
                document.getElementById("add_contentTitle").style.display = "";
                document.getElementById("edit").style.display = "";
                document.getElementById("uploadImg").setAttribute("class", "uploadImg2");
                document.getElementById("uploadImg").src = "images/imageAdd.png";
                document.getElementById("add_imgUrl").innerHTML = "images/imageAdd.png";

                document.getElementById("add-imgDel").style.marginRight = "34px";
            }else if(typeName == "教师"){
                allHide();
                $("#toAdd").click();
                document.getElementById("add_name").innerHTML = "<span class='import'>*</span>姓名";
                document.getElementById("add_title").placeholder = "姓名";
                document.getElementById("add_topTitle").innerHTML = "新增教师";
                document.getElementById("add_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
                document.getElementById("add-moto").style.display = "";
                document.getElementById("add-position").style.display = "";
                document.getElementById("add-priority").style.display = "";
                document.getElementById("add_contentTitle").style.display = "none";
                document.getElementById("edit").style.display = "none";
                document.getElementById("uploadImg").setAttribute("class", "uploadImg3");
                document.getElementById("uploadImg").src = "images/teacherAdd.png";
                document.getElementById("add_imgUrl").innerHTML = "images/teacherAdd.png";

                document.getElementById("add-imgDel").style.marginRight = "34px";
            }else if(typeName == "学生"){
                allHide();
                $("#toAdd").click();
                $("#add_stuPosition").empty();
                for(var p = 0;p<studentPosition.length;p++){
                    document.getElementById("add_stuPosition").innerHTML = document.getElementById("add_stuPosition").innerHTML+
                        '<option value="'+studentPosition[p]+'">'+studentPosition[p]+'</option>'
                }
                $("#add_star").empty();
                for(var k = 0;k<starList.length;k++){
                    document.getElementById("add_star").innerHTML = document.getElementById("add_star").innerHTML+
                        '<option value="'+starList[k]+'">'+starList[k]+'</option>'
                }
                document.getElementById("add_name").innerHTML = "<span class='import'>*</span>姓名";
                document.getElementById("add_title").placeholder = "姓名";
                document.getElementById("add_topTitle").innerHTML = "新增学生";
                document.getElementById("add_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
                document.getElementById("add-class").style.display = "";
                document.getElementById("add-sex").style.display = "";
                document.getElementById("add-age").style.display = "";
                document.getElementById("add-star").style.display = "";
                document.getElementById("add-hobby").style.display = "";
                document.getElementById("add-brief").style.display = "";
                document.getElementById("add-stuPosition").style.display = "";
                document.getElementById("add_contentTitle").style.display = "none";
                document.getElementById("edit").style.display = "none";

                document.getElementById("uploadImg").setAttribute("class", "uploadImg4");
                document.getElementById("uploadImg").src = "images/studentAdd.png";
                document.getElementById("add_imgUrl").innerHTML = "images/studentAdd.png";
                document.getElementById("add-imgDel").style.marginRight = "28px";
            } else if(typeName == "教师风采"){
                $("#toAddLabel").click();
                queryLabel(ZtreeId);
            }
        }
    });

    //新建文章
    $("#add_confirm").click(function(){
        var title = document.getElementById("add_title").value;
        var content = document.getElementById("edit").getElementsByClassName("fr-element")[0].innerHTML;
        var imageUrl = document.getElementById("add_imgUrl").innerHTML;
        var addTime = Date.parse(new Date(getNowFormatDate() + " 00:00:00"));
        var data = {
            title:title,
            content:content
        };
        if(typeName == "文章" || typeName == "基本概况"){
            if(typeName == "文章"){
                var type = 1;
            }else {
                type = 5;
            }
            var authorName = document.getElementById("add_author").value;
            var source = document.getElementById("add_source").value;
            var submitTime = document.getElementById("add_submitTime").value;
            var subtitle = document.getElementById("add_subtitle").value;
            var keywords = document.getElementById("add_keywords").value;
            var ext = {
                authorName:authorName,
                source:source,
                submitTime:submitTime,
                subtitle:subtitle,
                keywords:keywords
            };
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(submitTime == ""){
                modalinfo("请选择发布时间");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.ext = JSON.stringify(ext);
                data.imageUrl = imageUrl;
                data.submitTime = Date.parse(new Date(submitTime+ " 00:00:00"));
                data.labelId = 0;
            }
        }else if(typeName == "图片"){
            type = 2;
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(imageUrl == "images/imageAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "教师"){
            type = 3;
            var moto = document.getElementById("add_moto").value;
            var position = document.getElementById("add_position").value;
            var priority = document.getElementById("add_priority").value;
            ext = {
                moto:moto,
                position:position,
                priority:priority
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            } else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            } else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "学生"){
            type = 4;
            var addclass = document.getElementById("add_class").value;
            var sex = document.getElementById("add_sex").value;
            var age = document.getElementById("add_age").value;
            var star = document.getElementById("add_star").value;
            var hobby = document.getElementById("add_hobby").value;
            var brief = document.getElementById("add_brief").value;
            var position = document.getElementById("add_stuPosition").value;
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == "请选择"){
                modalinfo("请选择职位");
                return false;
            }else if(addclass==""){
                modalinfo("请输入班级");
                return false;
            } else if(sex=="0"){
                modalinfo("请选择性别");
                return false;
            }else if(age=="" || age == "0"){
                modalinfo("请输入年龄");
                return false;
            }else if(star=="请选择"){
                modalinfo("请选择星座");
                return false;
            }else if(hobby == ""){
                modalinfo("请输入爱好");
                return false;
            } else if(hobby.length>15){
                modalinfo("爱好字数不能大于15个字");
                return false;
            }else if(brief == ""){
                modalinfo("请输入标语");
                return false;
            } else if(brief.length>50){
                modalinfo("标语字数不能大于50个字");
                return false;
            }else if(imageUrl == "images/studentAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                ext = {
                    class:addclass,
                    sex:sex,
                    age:age,
                    star:star,
                    hobby:hobby,
                    brief:brief,
                    position:position
                };
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "教师风采"){
            type = 6;
            var moto = document.getElementById("add_moto").value;
            var position = document.getElementById("add_position").value;
            var priority = document.getElementById("add_priority").value;
            var labelId = document.getElementById("addLabel_id").innerHTML;
            ext = {
                moto:moto,
                position:position,
                priority:priority
            };
            if(labelId == ""){
                modalinfo("请选择标签");
            } else if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            } else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            } else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = labelId;
            }
        }
        if(document.getElementById("add_exam").checked == true){
            data.status = 2;
        }else{
            data.status = 1;
        }
        $.ajax({
            url : urladdr + "/web/article/add?token="+Mytoken,
            method : "POST",
            contentType:"application/json; charset=utf-8",
            data : JSON.stringify(data),
            success : function(data){
                if(data.code == 0){
                    modalinfo("新增成功");
                    $("#toArticle").click();
                    queryArticle(1,15,ZtreeId);

                }else{
                    modalinfo(data.msg);
                }
            }
        });
    });

    //编辑
    $("#edit_article").click(function(){
        var t = document.getElementById("article_table");
        var ext;
        var title;
        var imageUrl;
        var imgUrlID;
        var content;
        var type;
        var priority;
        var menuId;
        var labelId;
        var labelName;
        for(var i=0;i< t.rows.length;i++){
            if(t.rows[i].style.background == "rgb(223, 240, 216)" || t.rows[i].style.background == "rgb(223, 240, 216) none repeat scroll 0% 0%"){
                editInit();
                $("#toEdit").click();
                document.getElementById("columnType").innerHTML = "编辑";
                document.getElementById("image_type").innerHTML = "edit";
                var id = t.rows[i].cells[0].innerHTML;
                var status = t.rows[i].cells[12].innerHTML;
                $.ajax({
                    url : urladdr + "/web/article/info",
                    method : "GET",
                    data : {
                        id:id
                    },
                    async : false,
                    success : function(data){
                        if(data.code == 0){
                            ext = JSON.parse(data.data.ext);
                            title = data.data.title;
                            imageUrl = data.data.imageUrl;
                            imgUrlID = imgUrl + data.data.imageUrl;
                            content = data.data.content;
                            type = data.data.type;
                            priority = data.data.priority;
                            menuId = data.data.menuId;
                            labelId = data.data.labelId;
                            labelName = data.data.labelName;
                            if(data.data.status == 1 || data.data.status == 4){
                                document.getElementById("edit_draft").style.display = "";
                            }else{
                                document.getElementById("edit_draft").style.display = "none";
                            }
                        }else if(data.code == 404){
                            location.href = "404.html"
                        } else{
                            modalinfo(data.msg);
                        }
                    }
                });

                document.getElementById("edit_id").innerHTML = id;
                document.getElementById("edit_type").innerHTML = type;
                document.getElementById("edit_menuId").innerHTML = menuId;
                document.getElementById("edit_imgUrl").innerHTML = imageUrl;
                document.getElementById("edit_status").innerHTML = status;
                if(type == "1" || type == "5"){
                    editallHide();
                    document.getElementById("edit_name").innerHTML = "<span class='import'>*</span>标题";
                    document.getElementById("edit_title").placeholder = "标题";
                    if(type == "1"){
                        document.getElementById("edit_topTitle").innerHTML = "修改文章";
                    }else {
                        document.getElementById("edit_topTitle").innerHTML = "修改基本概况";
                    }
                    document.getElementById("edit_imgTitle").innerHTML = "封面图片";
                    document.getElementById("edit-author").style.display = "";
                    document.getElementById("edit-source").style.display = "";
                    document.getElementById("edit-subtitle").style.display = "";
                    document.getElementById("edit-keywords").style.display = "";
                    document.getElementById("edit-submitTime").style.display = "";
                    document.getElementById("edit_contentTitle").style.display = "";
                    document.getElementById("edit_edit").style.display = "";

                    document.getElementById("edit_title").value = title;
                    document.getElementById("edit_author").value = ext.authorName;
                    document.getElementById("edit_submitTime").value = ext.submitTime;
                    document.getElementById("edit_subtitle").value = ext.subtitle;
                    document.getElementById("edit_keywords").value = ext.keywords;
                    document.getElementById("edit_source").value = ext.source;
                    if(imageUrl == "images/articleAdd.png"){
                        document.getElementById("edituploadImg").src = imageUrl;
                    }else{
                        document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    }

                    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

                    document.getElementById("edituploadImg").setAttribute("class", "uploadImg1");
                    document.getElementById("edit-imgDel").style.marginRight = "56px";
                }else if(type == "2"){
                    editallHide();
                    document.getElementById("edit_name").innerHTML = "<span class='import'>*</span>标题";
                    document.getElementById("edit_title").placeholder = "标题";
                    document.getElementById("edit_topTitle").innerHTML = "修改图片";
                    document.getElementById("edit_imgTitle").innerHTML = "<span class='import'>*</span>封面图片";
                    document.getElementById("edit_contentTitle").style.display = "";
                    document.getElementById("edit_edit").style.display = "";

                    document.getElementById("edit_title").value = title;
                    document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

                    document.getElementById("edituploadImg").setAttribute("class", "uploadImg2");
                    document.getElementById("edit-imgDel").style.marginRight = "34px";

                    if(imageUrl == "images/imageAdd.png"){
                        document.getElementById("edituploadImg").src = imageUrl;
                    }else{
                        document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    }
                }else if(type == "3"){
                    editallHide();
                    $("#edit_position").empty();
                    document.getElementById("edit_name").innerHTML = "<span class='import'>*</span>姓名";
                    document.getElementById("edit_title").placeholder = "姓名";
                    document.getElementById("edit_topTitle").innerHTML = "修改教师";
                    document.getElementById("edit_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
                    document.getElementById("edit-moto").style.display = "";
                    document.getElementById("edit-position").style.display = "";
                    document.getElementById("edit-priority").style.display = "";
                    document.getElementById("edit_contentTitle").style.display = "none";
                    document.getElementById("edit_edit").style.display = "none";

                    document.getElementById("edit_title").value = title;
                    document.getElementById("edit_position").value = ext.position;
                    document.getElementById("edit_moto").value = ext.moto;
                    document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    document.getElementById("edit_priority").value = priority;
                    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

                    document.getElementById("edituploadImg").setAttribute("class", "uploadImg3");
                    document.getElementById("edit-imgDel").style.marginRight = "34px";

                    if(imageUrl == "images/teacherAdd.png"){
                        document.getElementById("edituploadImg").src = imageUrl;
                    }else{
                        document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    }
                }else if(type == "4"){
                    editallHide();
                    $("#edit_stuPosition").empty();
                    for(var p = 0;p<studentPosition.length;p++){
                        document.getElementById("edit_stuPosition").innerHTML = document.getElementById("edit_stuPosition").innerHTML+
                            '<option value="'+studentPosition[p]+'">'+studentPosition[p]+'</option>'
                    }
                    $("#edit_star").empty();
                    for(var k = 0;k<starList.length;k++){
                        document.getElementById("edit_star").innerHTML = document.getElementById("edit_star").innerHTML+
                            '<option value="'+starList[k]+'">'+starList[k]+'</option>'
                    }
                    document.getElementById("edit_name").innerHTML = "<span class='import'>*</span>姓名";
                    document.getElementById("edit_title").placeholder = "姓名";
                    document.getElementById("edit_topTitle").innerHTML = "修改学生";
                    document.getElementById("edit_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
                    document.getElementById("edit-class").style.display = "";
                    document.getElementById("edit-sex").style.display = "";
                    document.getElementById("edit-age").style.display = "";
                    document.getElementById("edit-star").style.display = "";
                    document.getElementById("edit-hobby").style.display = "";
                    document.getElementById("edit-brief").style.display = "";
                    document.getElementById("edit-stuPosition").style.display = "";
                    document.getElementById("edit_contentTitle").style.display = "none";
                    document.getElementById("edit_edit").style.display = "none";

                    document.getElementById("edituploadImg").setAttribute("class", "uploadImg4");
                    document.getElementById("edit-imgDel").style.marginRight = "28px";

                    document.getElementById("edit_title").value = title;
                    document.getElementById("edit_stuPosition").value = ext.position;
                    document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = content;
                    document.getElementById("edit_class").value = ext.class;
                    document.getElementById("edit_sex").value = ext.sex;

                    document.getElementById("edit_age").value = ext.age;
                    document.getElementById("edit_star").value = ext.star;
                    document.getElementById("edit_hobby").value = ext.hobby;
                    document.getElementById("edit_brief").value = ext.brief;

                    if(imageUrl == "images/studentAdd.png"){
                        document.getElementById("edituploadImg").src = imageUrl;
                    }else{
                        document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    }
                }else if(type == "6"){
                    editallHide();
                    $("#edit_position").empty();
                    document.getElementById("edit_name").innerHTML = "<span class='import'>*</span>姓名";
                    document.getElementById("edit_title").placeholder = "姓名";
                    document.getElementById("edit_topTitle").innerHTML = "修改教师";
                    document.getElementById("edit_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
                    document.getElementById("edit-moto").style.display = "";
                    document.getElementById("edit-position").style.display = "";
                    document.getElementById("edit-priority").style.display = "";
                    document.getElementById("editLabels").style.display = "";
                    document.getElementById("edit_contentTitle").style.display = "none";
                    document.getElementById("edit_edit").style.display = "none";

                    document.getElementById("editLabel_id").innerHTML = labelId;
                    document.getElementById("editLabel").innerHTML = labelName;
                    document.getElementById("edit_title").value = title;
                    document.getElementById("edit_position").value = ext.position;
                    document.getElementById("edit_moto").value = ext.moto;
                    document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    document.getElementById("edit_priority").value = priority;
                    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

                    document.getElementById("edituploadImg").setAttribute("class", "uploadImg3");
                    document.getElementById("edit-imgDel").style.marginRight = "34px";

                    if(imageUrl == "images/teacherAdd.png"){
                        document.getElementById("edituploadImg").src = imageUrl;
                    }else{
                        document.getElementById("edituploadImg").src = imgUrl + imageUrl;
                    }
                }
                break;
            }
        }
    });

    //编辑确定
    $("#edit_confirm").click(function(){
        var id = document.getElementById("edit_id").innerHTML;
        var title = document.getElementById("edit_title").value;
        var content = document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML;
        var imageUrl = document.getElementById("edit_imgUrl").innerHTML;
        var typen = document.getElementById("edit_type").innerHTML;
        var menuId = document.getElementById("edit_menuId").innerHTML;
        var addTime = Date.parse(new Date(getNowFormatDate() + " 00:00:00"));
        var status = document.getElementById("edit_status").innerHTML;
        if(status == "1"){
            var editStatus = 1;
        }else if(status == "2"){
            editStatus = 1;
        }else if(status == "3"){
            editStatus = 1;
        }else if(status == "4"){
            editStatus = 1;
        }
        var data = {
            id:id,
            title:title,
            content:content,
            status:editStatus
        };
        if(typen == "1" || typen == "5"){
            if(typen == "1"){
                var type = 1;
            }else{
                type = 5;
            }
            var authorName = document.getElementById("edit_author").value;
            var source = document.getElementById("edit_source").value;
            var submitTime = document.getElementById("edit_submitTime").value;
            var subtitle = document.getElementById("edit_subtitle").value;
            var keywords = document.getElementById("edit_keywords").value;
            var ext = {
                authorName:authorName,
                source:source,
                submitTime:submitTime,
                subtitle:subtitle,
                keywords:keywords
            };
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(submitTime == ""){
                modalinfo("请选择发布时间");
                return false;
            }else{
                data.type = type;
                data.menuId = menuId;
                data.ext = JSON.stringify(ext);
                data.imageUrl = imageUrl;
                data.submitTime = Date.parse(new Date(submitTime+ " 00:00:00"));
                data.labelId = 0;
            }
        }else if(typen == "2"){
            type = 2;
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(imageUrl == "images/imageAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "3"){
            type = 3;
            var moto = document.getElementById("edit_moto").value;
            var position = document.getElementById("edit_position").value;
            var priority = document.getElementById("edit_priority").value;
            ext = {
                moto:moto,
                position:position
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            } else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            }else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            } else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.priority = priority;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "4"){
            type = 4;
            var addclass = document.getElementById("edit_class").value;
            var sex = document.getElementById("edit_sex").value;
            var age = document.getElementById("edit_age").value;
            var star = document.getElementById("edit_star").value;
            var hobby = document.getElementById("edit_hobby").value;
            var brief = document.getElementById("edit_brief").value;
            var position = document.getElementById("edit_stuPosition").value;
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == "请选择"){
                modalinfo("请选择职位");
                return false;
            } else if(addclass==""){
                modalinfo("请输入班级");
                return false;
            } else if(sex=="0"){
                modalinfo("请选择性别");
                return false;
            }else if(age==""){
                modalinfo("请输入年龄");
                return false;
            }else if(star=="请选择"){
                modalinfo("请选择星座");
                return false;
            }else if(hobby == ""){
                modalinfo("请输入爱好");
                return false;
            } else if(hobby.length>15){
                modalinfo("爱好字数不能大于15个字");
                return false;
            } else if(brief == ""){
                modalinfo("请输入标语");
                return false;
            } else if(brief.length>50){
                modalinfo("标语字数不能大于50个字");
                return false;
            } else if(imageUrl == "images/studentAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                ext = {
                    class:addclass,
                    sex:sex,
                    age:age,
                    star:star,
                    hobby:hobby,
                    brief:brief,
                    position:position
                };
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "6"){
            type = 6;
            var moto = document.getElementById("edit_moto").value;
            var position = document.getElementById("edit_position").value;
            var priority = document.getElementById("edit_priority").value;
            var labelId = document.getElementById("editLabel_id").innerHTML;
            ext = {
                moto:moto,
                position:position
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            } else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            }else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            } else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.priority = priority;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = labelId;
            }
        }
        $.ajax({
            url : urladdr + "/web/article/update?token="+Mytoken,
            method : "POST",
            contentType:"application/json; charset=utf-8",
            data : JSON.stringify(data),
            success : function(data){
                if(data.code == 0){
                    modalinfo("编辑成功");
                    $("#toArticle").click();
                    queryArticle(1,15,ZtreeId);
                }else{
                    modalinfo(data.msg);
                }
            }
        });
    });

    //删除
    $("#delete_article").click(function(){
        var t = document.getElementById("article_table");
        ids = [];
        for(var i = 0;i< t.rows.length;i++){
            if(t.rows[i].cells[1].getElementsByTagName("input")[0].checked == true){
                ids.push(t.rows[i].cells[0].innerHTML);
            }
        }
        if(ids.length == 0){
            modalinfo("请勾选要删除的文章");
        }else{
            showmodal("#deletemodal");
        }
    });

    //确认删除
    $("#del_confirm").click(function(){
        var x = 0;
        if(ids.length != 0){
            for(var i = 0;i<ids.length;i++){
                var id = ids[i];
                var data={
                    token:Mytoken,
                    id:id
                };
                $.ajax({
                    url : urladdr + "/web/article/delete",
                    method : "POST",
                    data : data,
                    async : false,
                    success : function(data){
                        if(data.code == 0){
                            x++;
                        }else{
                            modalinfo(data.msg);
                            modalclose("#deletemodal");
                        }
                    }
                });
            }
        }
        setTimeout(function(){
            if(x == ids.length){
                modalinfo("删除成功");
                modalclose("#deletemodal");
                document.getElementById("allcheck").checked = false;
                queryArticle(1,15,ZtreeId);
            }
        },100);
    });

    //审核
    $("#exam_article").click(function(){
        var t = document.getElementById("article_table");
        ids = [];
        for(var i = 0;i< t.rows.length;i++){
            if(t.rows[i].cells[1].getElementsByTagName("input")[0].checked == true){
                ids.push(t.rows[i].cells[0].innerHTML);
            }
        }
        if(ids.length == 0){
            modalinfo("请勾选要审核的文章");
        }else{
            showmodal("#exammodal");
        }
    });

    //通过
    $("#exam_confirm").click(function(){
        var x = 0;
        if(ids.length != 0){
            for(var i = 0;i<ids.length;i++){
                var id = ids[i];
                var data={
                    token:Mytoken,
                    id:id,
                    status:2
                };
                $.ajax({
                    url : urladdr + "/web/article/audit",
                    method : "POST",
                    data : data,
                    async : false,
                    success : function(data){
                        if(data.code == 0){
                            x++;
                        }else{
                            modalinfo(data.msg);
                            modalclose("#exammodal");
                        }
                    }
                });
            }
        }
        setTimeout(function(){
            if(x == ids.length){
                modalinfo("审核通过");
                modalclose("#exammodal");
                document.getElementById("allcheck").checked = false;
                queryArticle(1,15,ZtreeId);
            }
        },100);
    });
    //详情页——通过
    $("#detail_adopt").click(function(){
        var id = document.getElementById("detail_id").innerHTML;
        var data={
            token:Mytoken,
            id:id,
            status:2
        };
        $.ajax({
            url : urladdr + "/web/article/audit",
            method : "POST",
            data : data,
            success : function(data){
                if(data.code == 0){
                    modalinfo("审核通过");
                    document.getElementById("detail_adopt").style.display = "none";
                    document.getElementById("detail_reject").style.display = "none";
                    queryArticle(1,15,ZtreeId);
                }else{
                    modalinfo(data.msg);
                    modalclose("#exammodal");
                }
            }
        });
    });

    //驳回
    $("#exam_cancel").click(function(){
        var x = 0;
        if(ids.length != 0){
            for(var i = 0;i<ids.length;i++){
                var id = ids[i];
                var data={
                    token:Mytoken,
                    id:id,
                    status:3
                };
                $.ajax({
                    url : urladdr + "/web/article/audit",
                    method : "POST",
                    data : data,
                    async : false,
                    success : function(data){
                        if(data.code == 0){
                            x++;
                        }else{
                            modalinfo(data.msg);
                            modalclose("#exammodal");
                        }
                    }
                });
            }
        }
        setTimeout(function(){
            if(x == ids.length){
                modalinfo("驳回成功");
                modalclose("#exammodal");
                document.getElementById("allcheck").checked = false;
                queryArticle(1,15,ZtreeId);
            }
        },100);
    });

    //详情页——驳回
    $("#detail_reject").click(function(){
        var id = document.getElementById("detail_id").innerHTML;
        var data={
            token:Mytoken,
            id:id,
            status:3
        };
        $.ajax({
            url : urladdr + "/web/article/audit",
            method : "POST",
            data : data,
            success : function(data){
                if(data.code == 0){
                    modalinfo("驳回成功");
                    document.getElementById("detail_adopt").style.display = "none";
                    document.getElementById("detail_reject").style.display = "none";
                    queryArticle(1,15,ZtreeId);
                }else{
                    modalinfo(data.msg);
                    modalclose("#exammodal");
                }
            }
        });
    });

    $("#image_confirm").click(function(){
        var type = document.getElementById("image_type").innerHTML;
        if(type == "add"){
            var img = "uploadImg";
            var imgId = "add_imgUrl"
        }else {
            img = "edituploadImg";
            imgId = "edit_imgUrl"
        }
        uplodbase64(img,imgId);
    });

    //查询
    $("#search").click(function(){
        queryArticle(1,15,ZtreeId);
    });

    $('#search_begin').datetimepicker({
        format: 'yyyy-mm-dd',//显示格式
        language:  'zh-CN',  //日期,
        todayHighlight: 1,//今天高亮
        minView: "month",//设置只显示到月份
        startView:2,
        forceParse: 0,
        showMeridian: 1,
        autoclose: 1,//选择后自动关闭
        todayBtn : "linked",
        endDate : new Date()
    }).on('changeDate',function(e){
        var startTime = e.date;
        $('#search_end').datetimepicker('setStartDate',startTime);
    });
    //结束时间：
    $('#search_end').datetimepicker({
        format: 'yyyy-mm-dd',//显示格式
        language:  'zh-CN',  //日期,
        todayHighlight: 1,//今天高亮
        minView: "month",//设置只显示到月份
        startView:2,
        forceParse: 0,
        showMeridian: 1,
        autoclose: 1,//选择后自动关闭
        todayBtn : "linked",
        endDate : new Date()
    }).on('changeDate',function(e){
        var endTime = e.date;
        $('#search_begin').datetimepicker('setEndDate',endTime);
    });

    //存草稿
    $("#add_draft").click(function(){
        var title = document.getElementById("add_title").value;
        var content = document.getElementById("edit").getElementsByClassName("fr-element")[0].innerHTML;
        var imageUrl = document.getElementById("add_imgUrl").innerHTML;
        var addTime = Date.parse(new Date(getNowFormatDate() + " 00:00:00"));
        var data = {
            title:title,
            content:content
        };
        if(typeName == "文章" || typeName == "基本概况"){
            if(typeName == "文章"){
                var type = 1;
            }else {
                type = 5;
            }
            var authorName = document.getElementById("add_author").value;
            var source = document.getElementById("add_source").value;
            var submitTime = document.getElementById("add_submitTime").value;
            var subtitle = document.getElementById("add_subtitle").value;
            var keywords = document.getElementById("add_keywords").value;
            var ext = {
                authorName:authorName,
                source:source,
                submitTime:submitTime,
                subtitle:subtitle,
                keywords:keywords
            };
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(submitTime == ""){
                modalinfo("请选择发布时间");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.ext = JSON.stringify(ext);
                data.imageUrl = imageUrl;
                data.submitTime = Date.parse(new Date(submitTime+ " 00:00:00"));
                data.labelId = 0;
            }
        }else if(typeName == "图片"){
            type = 2;
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(imageUrl == "images/imageAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "教师"){
            type = 3;
            var moto = document.getElementById("add_moto").value;
            var position = document.getElementById("add_position").value;
            var priority = document.getElementById("add_priority").value;
            ext = {
                moto:moto,
                position:position,
                priority:priority
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            }else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            } else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "学生"){
            type = 4;
            var addclass = document.getElementById("add_class").value;
            var sex = document.getElementById("add_sex").value;
            var age = document.getElementById("add_age").value;
            var star = document.getElementById("add_star").value;
            var hobby = document.getElementById("add_hobby").value;
            var brief = document.getElementById("add_brief").value;
            var position = document.getElementById("add_stuPosition").value;
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == "请选择"){
                modalinfo("请选择职位");
                return false;
            }else if(addclass==""){
                modalinfo("请输入班级");
                return false;
            } else if(sex=="0"){
                modalinfo("请选择性别");
                return false;
            }else if(age=="" || age == "0"){
                modalinfo("请输入年龄");
                return false;
            }else if(star=="请选择"){
                modalinfo("请选择星座");
                return false;
            }else if(hobby == ""){
                modalinfo("请输入爱好");
                return false;
            } else if(hobby.length>15){
                modalinfo("爱好字数不能大于15个字");
                return false;
            }else if(brief == ""){
                modalinfo("请输入标语");
                return false;
            } else if(brief.length>50){
                modalinfo("标语字数不能大于50个字");
                return false;
            }else if(imageUrl == "images/studentAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                ext = {
                    class:addclass,
                    sex:sex,
                    age:age,
                    star:star,
                    hobby:hobby,
                    brief:brief,
                    position:position
                };
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typeName == "教师风采"){
            type = 6;
            var moto = document.getElementById("add_moto").value;
            var position = document.getElementById("add_position").value;
            var priority = document.getElementById("add_priority").value;
            var labelId = document.getElementById("addLabel_id").innerHTML;
            ext = {
                moto:moto,
                position:position,
                priority:priority
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            }else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            } else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = ZtreeId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = labelId;
            }
        }
        data.status = 4;
        $.ajax({
            url : urladdr + "/web/article/add?token="+Mytoken,
            method : "POST",
            contentType:"application/json; charset=utf-8",
            data : JSON.stringify(data),
            success : function(data){
                if(data.code == 0){
                    modalinfo("存为草稿成功");
                    $("#toArticle").click();
                    queryArticle(1,15,ZtreeId);

                }else{
                    modalinfo(data.msg);
                }
            }
        });
    });

    $("#edit_draft").click(function(){
        var id = document.getElementById("edit_id").innerHTML;
        var title = document.getElementById("edit_title").value;
        var content = document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML;
        var imageUrl = document.getElementById("edit_imgUrl").innerHTML;
        var typen = document.getElementById("edit_type").innerHTML;
        var menuId = document.getElementById("edit_menuId").innerHTML;
        var addTime = Date.parse(new Date(getNowFormatDate() + " 00:00:00"));
        var data = {
            id:id,
            title:title,
            content:content,
            status:4
        };
        if(typen == "1" || typen == "5"){
            if(typen == "1"){
                var type = 1;
            }else {
                type = 5;
            }
            var authorName = document.getElementById("edit_author").value;
            var source = document.getElementById("edit_source").value;
            var submitTime = document.getElementById("edit_submitTime").value;
            var subtitle = document.getElementById("edit_subtitle").value;
            var keywords = document.getElementById("edit_keywords").value;
            var ext = {
                authorName:authorName,
                source:source,
                submitTime:submitTime,
                subtitle:subtitle,
                keywords:keywords
            };
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(submitTime == ""){
                modalinfo("请选择发布时间");
                return false;
            }else{
                data.type = type;
                data.menuId = menuId;
                data.ext = JSON.stringify(ext);
                data.imageUrl = imageUrl;
                data.submitTime = Date.parse(new Date(submitTime+ " 00:00:00"));
                data.labelId = 0;
            }
        }else if(typen == "2"){
            type = 2;
            if(title==""){
                modalinfo("请输入标题");
                return false;
            }else if(imageUrl == "images/imageAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "3"){
            type = 3;
            var moto = document.getElementById("edit_moto").value;
            var position = document.getElementById("edit_position").value;
            var priority = document.getElementById("edit_priority").value;
            ext = {
                moto:moto,
                position:position
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            }else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            }else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            } else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.priority = priority;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "4"){
            type = 4;
            var addclass = document.getElementById("edit_class").value;
            var sex = document.getElementById("edit_sex").value;
            var age = document.getElementById("edit_age").value;
            var star = document.getElementById("edit_star").value;
            var hobby = document.getElementById("edit_hobby").value;
            var brief = document.getElementById("edit_brief").value;
            var position = document.getElementById("edit_stuPosition").value;
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == "请选择"){
                modalinfo("请选择职位");
                return false;
            } else if(addclass==""){
                modalinfo("请输入班级");
                return false;
            } else if(sex=="0"){
                modalinfo("请输入选择");
                return false;
            }else if(age==""){
                modalinfo("请输入年龄");
                return false;
            }else if(star=="请选择"){
                modalinfo("请选择星座");
                return false;
            }else if(hobby == ""){
                modalinfo("请输入爱好");
                return false;
            } else if(hobby.length>15){
                modalinfo("爱好字数不能大于15个字");
                return false;
            } else if(brief == ""){
                modalinfo("请输入标语");
                return false;
            } else if(brief.length>50){
                modalinfo("标语字数不能大于50个字");
                return false;
            } else if(imageUrl == "images/studentAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            }else{
                ext = {
                    class:addclass,
                    sex:sex,
                    age:age,
                    star:star,
                    hobby:hobby,
                    brief:brief,
                    position:position
                };
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = 0;
            }
        }else if(typen == "6"){
            type = 6;
            var moto = document.getElementById("edit_moto").value;
            var position = document.getElementById("edit_position").value;
            var priority = document.getElementById("edit_priority").value;
            var labelId = document.getElementById("editLabel_id").innerHTML;
            ext = {
                moto:moto,
                position:position
            };
            if(title==""){
                modalinfo("请输入姓名");
                return false;
            }else if(position == ""){
                modalinfo("请输入职位");
                return false;
            }else if(position.length > 12){
                modalinfo("职位不能大于12个字");
                return false;
            }else if(moto == ""){
                modalinfo("请输入个人简介");
                return false;
            } else if(moto.length>150){
                modalinfo("个人简介字数不能超过150个字");
                return false;
            }else if(imageUrl == "images/teacherAdd.png"){
                modalinfo("请先上传一张图片");
                return false;
            } else{
                data.type = type;
                data.menuId = menuId;
                data.imageUrl = imageUrl;
                data.priority = priority;
                data.ext = JSON.stringify(ext);
                data.submitTime = addTime;
                data.labelId = labelId;
            }
        }
        $.ajax({
            url : urladdr + "/web/article/update?token="+Mytoken,
            method : "POST",
            contentType:"application/json; charset=utf-8",
            data : JSON.stringify(data),
            success : function(data){
                if(data.code == 0){
                    modalinfo("存为草稿成功");
                    $("#toArticle").click();
                    queryArticle(1,15,ZtreeId);
                }else{
                    modalinfo(data.msg);
                }
            }
        });
    });

    //列表同步
    $("#synchro").click(function(){
        var t = document.getElementById("article_table");
        ids = [];
        var x = 0;
        for(var i = 0;i< t.rows.length;i++){
            if(t.rows[i].cells[1].getElementsByTagName("input")[0].checked == true){
                ids.push(t.rows[i].cells[0].innerHTML);
                document.getElementById("list_type").innerHTML = t.rows[i].cells[5].innerHTML;
                x = i;
            }
        }
        if(ids.length == 0){
            modalinfo("请勾选要同步的文章");
        }else if(ids.length>1){
            modalinfo("只能选择一篇文章进行同步");
        }else if(t.rows[x].cells[5].innerHTML == "教师风采"){
            modalinfo("教师风采类型的文章不能同步");
        }
        else{
            document.getElementById("columnType").innerHTML = "列表";
            selectColumn();
        }
    });

    //选择同步栏目
    $("#column_confirm").click(function(){
        var addNowType = document.getElementById("add_topTitle").innerHTML;
        var columnType = document.getElementById("columnType").innerHTML;
        if(zTreeSelect.length == 0){
            modalinfo("请选择栏目");
            modalclose("#columnmodal");
        }else{
            document.getElementById("list_synchro").innerHTML = "";
            if(columnType == "编辑"){
                if(addNowType == "修改文章" && addNowType == "修改基本概况"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 1 && zTreeSelect[i].type != 5){
                            modalinfo("该类型只能分享至文章类型或基本概况类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(addNowType == "修改图片"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 2){
                            modalinfo("该类型只能分享至图片类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(addNowType == "修改教师"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 3){
                            modalinfo("该类型只能分享至教师类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(addNowType == "修改学生"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 4){
                            modalinfo("该类型只能分享至学生类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }
                for(var j = 0;j<zTreeSelect.length;j++){
                    if(j == 0){
                        var list = zTreeSelect[j].id;
                    }else{
                        list = list + "," + zTreeSelect[j].id;
                    }
                }
                document.getElementById("edit_synchro").innerHTML = list;

                var articleId = document.getElementById("edit_id").innerHTML;
                for(var j = 0;j<zTreeSelect.length;j++){
                    var data = {
                        articleId:articleId,
                        menuId:zTreeSelect[j].id,
                        token:Mytoken
                    };
                    $.ajax({
                        url : urladdr + "/web/article/paste",
                        method : "POST",
                        data : data,
                        async:false,
                        success : function(data){
                            if(data.code == 0){
                                modalinfo("同步成功");
                                modalclose("#columnmodal");
                                queryArticle(1,15,ZtreeId);
                            }else{
                                modalinfo(data.msg);
                            }
                        }
                    });
                }
            }else if(columnType == "列表"){
                var listType = document.getElementById("list_type").innerHTML;
                if(listType == "文章" && listType == "基本概况"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 1 && zTreeSelect[i].type != 5){
                            modalinfo("该类型只能分享至文章类型或基本概况类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(listType == "图片"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 2){
                            modalinfo("该类型只能分享至图片类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(listType == "教师"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 3){
                            modalinfo("该类型只能分享至教师类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(listType == "学生"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 4){
                            modalinfo("该类型只能分享至学生类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }
                for(var j = 0;j<zTreeSelect.length;j++){
                    var data = {
                        articleId:ids[0],
                        menuId:zTreeSelect[j].id,
                        token:Mytoken
                    };
                    $.ajax({
                        url : urladdr + "/web/article/paste",
                        method : "POST",
                        data : data,
                        async:false,
                        success : function(data){
                            if(data.code == 0){
                                modalinfo("同步成功");
                                modalclose("#columnmodal");
                                queryArticle(1,15,ZtreeId);
                            }else{
                                modalinfo(data.msg);
                            }
                        }
                    });
                }
            }else if(columnType == "详情"){
                var articleId = document.getElementById("detail_id").innerHTML;
                var articleType = document.getElementById("detail_type").innerHTML;
                if(articleType == "1" && articleType == "5"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 1 && zTreeSelect[i].type != 5){
                            modalinfo("该类型只能分享至文章类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(articleType == "2"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 2){
                            modalinfo("该类型只能分享至图片类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(articleType == "3"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 3){
                            modalinfo("该类型只能分享至教师类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }else if(articleType == "4"){
                    for(var i=0;i<zTreeSelect.length;i++){
                        if(zTreeSelect[i].type != 4){
                            modalinfo("该类型只能分享至学生类型的栏目");
                            modalclose("#columnmodal");
                            return false;
                        }
                    }
                }
                for(var j = 0;j<zTreeSelect.length;j++){
                    var data = {
                        articleId:articleId,
                        menuId:zTreeSelect[j].id,
                        token:Mytoken
                    };
                    $.ajax({
                        url : urladdr + "/web/article/paste",
                        method : "POST",
                        data : data,
                        async:false,
                        success : function(data){
                            if(data.code == 0){
                                modalinfo("同步成功");
                                modalclose("#columnmodal");
                                queryArticle(1,15,ZtreeId);
                            }else{
                                modalinfo(data.msg);
                            }
                        }
                    });
                }
            } else{
                modalinfo("未知错误");
            }
        }
    });

    $("#add_synchro_btn").click(function(){
        document.getElementById("columnType").innerHTML = "新增";
        selectColumn();
    });

    $("#edit_synchro_btn").click(function(){
        var type = document.getElementById("edit_type").innerHTML;
        document.getElementById("columnType").innerHTML = "编辑";
        if(type == 6){
            modalinfo("教师风采类型文章不可同步");
        }else{
            selectColumn();
        }
    });

    $("#detail_synchro_btn").click(function(){
        var type = document.getElementById("detail_type").innerHTML;
        document.getElementById("columnType").innerHTML = "详情";
        if(type == 6){
            modalinfo("教师风采类型文章不可同步");
        }else{
            selectColumn();
        }
    });

    queryColumn();
    queryArticle(1,15,0);
});

function allHide(){
    document.getElementById("add-author").style.display = "none";
    document.getElementById("add-source").style.display = "none";
    document.getElementById("add-subtitle").style.display = "none";
    document.getElementById("add-keywords").style.display = "none";
    document.getElementById("add-submitTime").style.display = "none";
    document.getElementById("add-moto").style.display = "none";
    document.getElementById("add-class").style.display = "none";
    document.getElementById("add-sex").style.display = "none";
    document.getElementById("add-age").style.display = "none";
    document.getElementById("add-star").style.display = "none";
    document.getElementById("add-hobby").style.display = "none";
    document.getElementById("add-brief").style.display = "none";
    document.getElementById("add-position").style.display = "none";
    document.getElementById("add-stuPosition").style.display = "none";
    document.getElementById("add-priority").style.display = "none";
    document.getElementById("addLabels").style.display = "none";
}

function addInit(){
    document.getElementById("add_title").value = "";
    document.getElementById("add_subtitle").value = "";
    document.getElementById("add_keywords").value = "";
    document.getElementById("add_author").value = "";
    document.getElementById("add_source").value = "";
    document.getElementById("add_submitTime").value = "";
    document.getElementById("upload").value = "";
    document.getElementById("edit").getElementsByClassName("fr-element")[0].innerHTML = "";
    document.getElementById("add_moto").value = "";
    document.getElementById("add_sex").value = '0';
    document.getElementById("add_age").value = "0";
    document.getElementById("add_star").value = "";
    document.getElementById("add_hobby").value = "";
    document.getElementById("add_brief").value = "";
    document.getElementById("add_position").value = "";
    document.getElementById("add_stuPosition").value = "0";
    document.getElementById("add_priority").value = "0";
    document.getElementById("add_submitTime").value = getNowFormatDate();
    document.getElementById("addLabel_id").innerHTML = "";
    document.getElementById("addLabel").innerHTML = "";
}

function editallHide(){
    document.getElementById("edit-author").style.display = "none";
    document.getElementById("edit-source").style.display = "none";
    document.getElementById("edit-subtitle").style.display = "none";
    document.getElementById("edit-keywords").style.display = "none";
    document.getElementById("edit-submitTime").style.display = "none";
    document.getElementById("edit-moto").style.display = "none";
    document.getElementById("edit-class").style.display = "none";
    document.getElementById("edit-sex").style.display = "none";
    document.getElementById("edit-age").style.display = "none";
    document.getElementById("edit-star").style.display = "none";
    document.getElementById("edit-hobby").style.display = "none";
    document.getElementById("edit-brief").style.display = "none";
    document.getElementById("edit-position").style.display = "none";
    document.getElementById("edit-stuPosition").style.display = "none";
    document.getElementById("edit-priority").style.display = "none";
    document.getElementById("editLabels").style.display = "none";
}

function detailallHide(){
    document.getElementById("detail-author").style.display = "none";
    document.getElementById("detail-source").style.display = "none";
    document.getElementById("detail-subtitle").style.display = "none";
    document.getElementById("detail-keywords").style.display = "none";
    document.getElementById("detail-submitTime").style.display = "none";
    document.getElementById("detail-moto").style.display = "none";
    document.getElementById("detail-class").style.display = "none";
    document.getElementById("detail-sex").style.display = "none";
    document.getElementById("detail-age").style.display = "none";
    document.getElementById("detail-star").style.display = "none";
    document.getElementById("detail-hobby").style.display = "none";
    document.getElementById("detail-brief").style.display = "none";
    document.getElementById("detail-position").style.display = "none";
    document.getElementById("detail-priority").style.display = "none";
    document.getElementById("detailLabels").style.display = "none";
}

function editInit(){
    document.getElementById("edit_title").value = "";
    document.getElementById("edit_author").value = "";
    document.getElementById("edit_subtitle").value = "";
    document.getElementById("edit_keywords").value = "";
    document.getElementById("edit_source").value = "";
    document.getElementById("edit_submitTime").value = "";
    document.getElementById("editupload").value = "";
    document.getElementById("edit_edit").getElementsByClassName("fr-element")[0].innerHTML = "";
    document.getElementById("edit_moto").value = "";
    document.getElementById("edit_sex").value = '0';
    document.getElementById("edit_age").value = "0";
    document.getElementById("edit_star").value = "";
    document.getElementById("edit_hobby").value = "";
    document.getElementById("edit_brief").value = "";
    document.getElementById("edit_position").value = "";
    document.getElementById("edit_stuPosition").value = "0";
    document.getElementById("edit_priority").value = "0";
    document.getElementById("editLabel_id").innerHTML = "";
    document.getElementById("editLabel").innerHTML = "";
}

function detailInit(oc){
    document.getElementById("detail_title").disabled = oc;
    document.getElementById("detail_subtitle").disabled = oc;
    document.getElementById("detail_keywords").disabled = oc;
    document.getElementById("detail_author").disabled = oc;
    document.getElementById("detail_source").disabled = oc;
    document.getElementById("detail_submitTime").disabled = oc;
    document.getElementById("detail_position").disabled = oc;
    document.getElementById("detail_class").disabled = oc;
    document.getElementById("detail_sex").disabled = oc;
    document.getElementById("detail_age").disabled = oc;
    document.getElementById("detail_star").disabled = oc;
    document.getElementById("detail_hobby").disabled = oc;
    document.getElementById("detail_brief").disabled = oc;
    document.getElementById("detail_priority").disabled = oc;
    document.getElementById("detail_edit").disabled = oc;
    document.getElementById("detail_moto").disabled = oc;
}

function queryArticle(page,pageSize,menuId){
    var title = document.getElementById("search_title").value;
    var creatorName = document.getElementById("search_name").value;
    var search_type = document.getElementById("search_type").value;
    var status = document.getElementById("search_status").value;
    var begin = document.getElementById("search_begin").value;
    var end = document.getElementById("search_end").value;
    var d1 = parseInt(getTime(begin));
    var d2 = parseInt(getTime(end));
    if(begin == "" && end !=""){
        modalinfo("请输入起始日期");
        return false;
    }else if(begin!="" && end == ""){
        modalinfo("请输入截止日期");
        return false;
    }else if(d1>d2){
        modalinfo("起始日期不能大于截止日期");
        return false;
    }else{
        var data = {
            token:Mytoken,
            page:page,
            pageSize:pageSize,
            menuId:menuId,
            status:status
        }
        if(title!=""){
            data.title = title;
        }
        if(creatorName != ""){
            data.creatorName = creatorName;
        }
        if(search_type != "0"){
            data.type = search_type;
        }
        if(begin!="" && end!=""){
            data.begin = begin;
            data.end = end;
        }
        $.ajax({
            url : urladdr + "/web/article/list",
            method : "GET",
            data : data,
            async:false,
            success : function(data){
                if(data.code == 0){
                    $("#article_table").empty();
                    $.each(data.data.list,function(i,date){
                        var color = "";
                        if(date.status == 1){
                            color = "blueColor";
                        }else if(date.status == 2){
                            color = "greenColor";
                        }else if(date.status == 3){
                            color = "redColor";
                        }else if(date.status == 4){
                            color = "brownColor";
                        }
                        if(date.content.length>20){
                            var content = date.content;
                            content = content.substring(0,20)+"···";
                        }else{
                            content = date.content
                        }
                        var num = (page -1)*15 + (i+1);
                        var menuName;
                        for(var j = 0;j < datas.length; j++){
                            if(date.menuId == datas[j].id){
                                menuName = datas[j].name;
                                break;
                            }
                        }
                        var dateTime = date.addTime;
                        if(dateTime!=null){
                            dateTime = dateTime.split(" ");
                            var time = dateTime[0];
                        }
                        if(date.type == 1){
                            var ext = JSON.parse(date.ext);
                            document.getElementById("article_table").innerHTML = document.getElementById("article_table").innerHTML +
                                '<tr>'+
                                '<td class="hidden">'+date.id+'</td>' +
                                '<td style="width:30px"><input type="checkbox"></td>'+
                                '<td style="width: 50px">'+num+'</td>'+
                                '<td>'+date.title+'</td>' +
                                '<td>'+menuName+'</td>'+
                                '<td>'+type[date.type]+'</td>' +
                                '<td>'+date.userName+'</td><td class='+color+'>'+statu[date.status]+'</td>'+
                                '<td style="width: 200px">'+ext.submitTime+'</td>'+
                                '<td style="width: 200px">'+date.addTime+'</td>'+
                                '<td>'+date.hit+'</td>'+
                                '<td><a onclick="detail('+i+')">详情</a></td>'+
                                '<td class="hidden">'+date.status+'</td>'+
                                '</tr>'
                        }else if(date.type == 6){
                            document.getElementById("article_table").innerHTML = document.getElementById("article_table").innerHTML +
                                '<tr>'+
                                '<td class="hidden">'+date.id+'</td>' +
                                '<td style="width:30px"><input type="checkbox"></td>'+
                                '<td style="width: 50px">'+num+'</td>'+
                                '<td>'+date.title+'('+date.labelName+')</td>' +
                                '<td>'+menuName+'</td>'+
                                '<td>'+type[date.type]+'</td>' +
                                '<td>'+date.userName+'</td><td class='+color+'>'+statu[date.status]+'</td>'+
                                '<td style="width: 200px">'+time+'</td>'+
                                '<td style="width: 200px">'+date.addTime+'</td>'+
                                '<td>'+date.hit+'</td>'+
                                '<td><a onclick="detail('+i+')">详情</a></td>'+
                                '<td class="hidden">'+date.status+'</td>'+
                                '</tr>'
                        }else{
                            document.getElementById("article_table").innerHTML = document.getElementById("article_table").innerHTML +
                                '<tr>'+
                                '<td class="hidden">'+date.id+'</td>' +
                                '<td style="width:30px"><input type="checkbox"></td>'+
                                '<td style="width: 50px">'+num+'</td>'+
                                '<td>'+date.title+'</td>' +
                                '<td>'+menuName+'</td>'+
                                '<td>'+type[date.type]+'</td>' +
                                '<td>'+date.userName+'</td><td class='+color+'>'+statu[date.status]+'</td>'+
                                '<td style="width: 200px">'+time+'</td>'+
                                '<td style="width: 200px">'+date.addTime+'</td>'+
                                '<td>'+date.hit+'</td>'+
                                '<td><a onclick="detail('+i+')">详情</a></td>'+
                                '<td class="hidden">'+date.status+'</td>'+
                                '</tr>'
                        }
                    });
                    $("#page").pagination({
                        pages: data.data.totalPage,
                        cssStyle: 'light-theme',
                        displayedPages:5,
                        edges:2,
                        currentPage:page
                    });
                    document.getElementById("recordCount").innerHTML = data.data.totalCount;
                    document.getElementById("pageCount").innerHTML = data.data.totalPage;
                    clicktable('article_table');
                }else{
                    modalinfo(data.msg);
                }
            }
        });
    }
}

function queryColumn(){
    $.ajax({
        url : urladdr + "/web/menu/list",
        method : "GET",
        data : {
            token:Mytoken
        },
        async:false,
        success : function(data){
            if(data.code == 0){
                zNodes.splice(0,zNodes.length);
                datas.splice(0,datas.length);
                $.each(data.data,function(i,date){
                    var da ={
                        id:date.id,name:date.title,parentId:date.parentId,height:date.height,type:date.type,icon:date.icon,type:date.type
                    };
                    datas.push(da);

                    if(date.height == 0){
                        var d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", open:true, iconSkin:"pIcon01",type:date.type
                        };
                    }else if(date.height == 1){
                        d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", open:true, iconSkin:"icon01",type:date.type
                        };
                    }else if(date.height == 2){
                        d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", iconSkin:"icon03",type:date.type
                        };
                    }
                    zNodes.push(d);
                });
                setTimeout(function(){
                    $.fn.zTree.init($("#tree"), setting, zNodes);
                },100)
            }else{
                modalinfo(data.msg);
            }
        }
    });
}

function uploadImg(id,imgId){
    var formData = new FormData();
    formData.append('image', $("#" + id)[0].files[0]);
    formData.append('token', Mytoken);
    $.ajax({
        url: urladdr + "/web/uploadImage",
        method: "POST",
        data: formData,
        processData: false,
        contentType: false,
        success : function(data){
            if(data.code == 0){
                var url = imgUrl + "/" + data.data;
                document.getElementById(imgId).src = url;
            }else{
                modalinfo(data.msg);
            }
        }
    });
}

//全选
function allcheck(obj){
    var t = document.getElementById("article_table");
    if(obj.checked == true){
        for(var i = 0;i< t.rows.length;i++){
            t.rows[i].cells[1].getElementsByTagName("input")[0].checked = true;
        }
    }else{
        for(var i = 0;i< t.rows.length;i++){
            t.rows[i].cells[1].getElementsByTagName("input")[0].checked = false;
        }
    }
}

function imageClickAdd(id){
    $("#"+id).click();
    var file = document.getElementById(id);
    if (file.outerHTML) {
        file.outerHTML = file.outerHTML;
    } else { // FF(包括3.5)
        file.value = "";
    }
    document.getElementById(id).focus();
    var type = typeName;
    var $image = $('#image');
    $image.empty();
    if(type == "文章" || type == "基本概况"){
        $image.cropper('setAspectRatio',194/124);
    }else if(type == "图片"){
        $image.cropper('setAspectRatio',420/280);
    }else if(type == "教师" || type == "教师风采"){
        $image.cropper('setAspectRatio',199/246);
    }else if(type == "学生"){
        $image.cropper('setAspectRatio',210/260);
    }
}


function imageClickEdit(id){
    $("#"+id).click();
    var file = document.getElementById(id);
    if (file.outerHTML) {
        file.outerHTML = file.outerHTML;
    } else { // FF(包括3.5)
        file.value = "";
    }
    document.getElementById(id).focus();
    var type = document.getElementById("edit_type").innerHTML;
    var $image = $('#image');
    $image.empty();
    if(type == "1" || type == "5"){
        $image.cropper('setAspectRatio',194/124);
    }else if(type == "2"){
        $image.cropper('setAspectRatio',420/280);
    }else if(type == "3" || type == "6"){
        $image.cropper('setAspectRatio',199/246);
    }else if(type == "4"){
        $image.cropper('setAspectRatio',210/260);
    }
}

function uplodbase64(imgId,imgUrlId) {
    var $image = $('#image');
    var $result = $('#result');

    var croppedCanvas;
    var roundedCanvas;

    if (!croppable) {
        return;
    }
    // Crop
    croppedCanvas = $image.cropper('getCroppedCanvas');
    // Round
    roundedCanvas = getRoundedCanvas(croppedCanvas);

    // Show
    $result.html('<img src="' + croppedCanvas.toDataURL() + '">');
    var x = croppedCanvas.toDataURL();
    modalclose("#imagemodal");
    showmodal("#progressmodal");
    setTimeout(function () {
        var base64 = x;
        base64 = base64.split(",");
        var imageData = new FormData();
        imageData.append('base64', base64[1]);
        imageData.append('token', Mytoken);
        $.ajax({
            url: urladdr+"/web/uploadBase64Image?token="+Mytoken,
            method: "POST",
            data: imageData,
            processData: false,
            contentType: false,
            ////这里我们先拿到jQuery产生的 XMLHttpRequest对象，为其增加 progress 事件绑定，然后再返回交给ajax使用
            xhr: function () {
                var xhr = $.ajaxSettings.xhr();
                if (onprogress && xhr.upload) {
                    xhr.upload.addEventListener("progress", onprogress, false);
                    return xhr;
                }
            },
            success: function (data) {
                if (data.code == 0) {
                    var imageUrl = data.data;
                    document.getElementById(imgId).src = imgUrl+imageUrl;
                    document.getElementById(imgUrlId).innerHTML = imageUrl;
                    setTimeout(function(){
                        modalclose("#progressmodal");
                    },500);
                }else{
                    modalclose("#imagemodal");
                    modalinfo(data.msg);
                }
            }
        })
    }, 500);
}

function detail(i){
    var t = document.getElementById("article_table");
    detailInit(true);
    $("#toDetail").click();
    var title;
    var imageUrl;
    var imgUrlID;
    var content;
    var ext;
    var type;
    var priority;
    var status;
    var menuId;
    var labelId;
    var labelName;
    document.getElementById("image_type").innerHTML = "edit";
    var id = t.rows[i].cells[0].innerHTML;
    $.ajax({
        url : urladdr + "/web/article/info",
        method : "GET",
        data : {
            id:id
        },
        async : false,
        success : function(data){
            if(data.code == 0){
                ext = JSON.parse(data.data.ext);
                title = data.data.title;
                imageUrl = data.data.imageUrl;
                imgUrlID = imgUrl + data.data.imageUrl;
                content = data.data.content;
                type = data.data.type;
                priority = data.data.priority;
                menuId = data.data.menuId;
                status = data.data.status;
                labelId = data.data.labelId;
                labelName = data.data.labelName;
            }else if(data.code == 404){
                location.href = "404.html"
            } else{
                modalinfo(data.msg);
            }
        }
    });

    if(status!= 1){
        document.getElementById("detail_adopt").style.display = "none";
        document.getElementById("detail_reject").style.display = "none";
    }else{
        document.getElementById("detail_adopt").style.display = "";
        document.getElementById("detail_reject").style.display = "";
    }
    document.getElementById("detail_id").innerHTML = id;
    document.getElementById("detail_type").innerHTML = type;
    document.getElementById("detail_menuId").innerHTML = menuId;
    if(type == "1" || type == "5"){
        detailallHide();
        document.getElementById("detail_name").innerHTML = "<span class='import'>*</span>标题";
        document.getElementById("detail_title").placeholder = "标题";
        document.getElementById("detail_imgTitle").innerHTML = "封面图片";
        document.getElementById("detail-author").style.display = "";
        document.getElementById("detail-source").style.display = "";
        document.getElementById("detail-subtitle").style.display = "";
        document.getElementById("detail-keywords").style.display = "";
        document.getElementById("detail-submitTime").style.display = "";
        document.getElementById("detail_contentTitle").style.display = "";
        document.getElementById("detail_edit").style.display = "";

        document.getElementById("detail_title").value = title;
        document.getElementById("detail_author").value = ext.authorName;
        document.getElementById("detail_submitTime").value = ext.submitTime;
        document.getElementById("detail_subtitle").value = ext.subtitle;
        document.getElementById("detail_keywords").value = ext.keywords;
        document.getElementById("detail_source").value = ext.source;
        if(imageUrl == "images/articleAdd.png"){
            document.getElementById("detailuploadImg").src = imageUrl;
        }else{
            document.getElementById("detailuploadImg").src = imgUrl + imageUrl;
        }
        document.getElementById("detail_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

        document.getElementById("detailuploadImg").setAttribute("class", "uploadImg1");
    }else if(type == "2"){
        detailallHide();
        document.getElementById("detail_name").innerHTML = "<span class='import'>*</span>标题";
        document.getElementById("detail_title").placeholder = "标题";
        document.getElementById("detail_imgTitle").innerHTML = "<span class='import'>*</span>封面图片";
        document.getElementById("detail_contentTitle").style.display = "";
        document.getElementById("detail_edit").style.display = "";

        document.getElementById("detail_title").value = title;
        document.getElementById("detailuploadImg").src = imgUrl + imageUrl;
        document.getElementById("detail_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

        document.getElementById("detailuploadImg").setAttribute("class", "uploadImg2");
    }else if(type == "3"){
        detailallHide();
        $("#edit_position").empty();
        document.getElementById("detail_name").innerHTML = "<span class='import'>*</span>姓名";
        document.getElementById("detail_title").placeholder = "姓名";
        document.getElementById("detail_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
        document.getElementById("detail-moto").style.display = "";
        document.getElementById("detail-position").style.display = "";
        document.getElementById("detail-priority").style.display = "";
        document.getElementById("detail_contentTitle").style.display = "none";
        document.getElementById("detail_edit").style.display = "none";

        document.getElementById("detail_title").value = title;
        document.getElementById("detail_position").value = ext.position;
        document.getElementById("detail_moto").value = ext.moto;
        document.getElementById("detailuploadImg").src = imgUrl + imageUrl;
        document.getElementById("detail_priority").value = priority;
        document.getElementById("detail_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

        document.getElementById("detailuploadImg").setAttribute("class", "uploadImg3");
    }else if(type == "4"){
        detailallHide();
        $("#edit_position").empty();
        $("#detail_star").empty();
        for(var k = 0;k<starList.length;k++){
            document.getElementById("detail_star").innerHTML = document.getElementById("detail_star").innerHTML+
                '<option value="'+starList[k]+'">'+starList[k]+'</option>'
        }
        document.getElementById("detail_name").innerHTML = "<span class='import'>*</span>姓名";
        document.getElementById("detail_title").placeholder = "姓名";
        document.getElementById("detail_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
        document.getElementById("detail-class").style.display = "";
        document.getElementById("detail-sex").style.display = "";
        document.getElementById("detail-age").style.display = "";
        document.getElementById("detail-star").style.display = "";
        document.getElementById("detail-hobby").style.display = "";
        document.getElementById("detail-brief").style.display = "";
        document.getElementById("detail-position").style.display = "";
        document.getElementById("detail_contentTitle").style.display = "none";
        document.getElementById("detail_edit").style.display = "none";

        document.getElementById("detailuploadImg").setAttribute("class", "uploadImg4");

        document.getElementById("detail_title").value = title;
        document.getElementById("detail_position").value = ext.position;
        document.getElementById("detailuploadImg").src = imgUrl + imageUrl;
        document.getElementById("detail_edit").getElementsByClassName("fr-element")[0].innerHTML = content;
        document.getElementById("detail_class").value = ext.class;
        document.getElementById("detail_sex").value = ext.sex;

        document.getElementById("detail_age").value = ext.age;
        document.getElementById("detail_star").value = ext.star;
        document.getElementById("detail_hobby").value = ext.hobby;
        document.getElementById("detail_brief").value = ext.brief;
    }else if(type == "6"){
        detailallHide();
        $("#edit_position").empty();
        document.getElementById("detail_name").innerHTML = "<span class='import'>*</span>姓名";
        document.getElementById("detail_title").placeholder = "姓名";
        document.getElementById("detail_imgTitle").innerHTML = "<span class='import'>*</span>图片上传";
        document.getElementById("detail-moto").style.display = "";
        document.getElementById("detail-position").style.display = "";
        document.getElementById("detail-priority").style.display = "";
        document.getElementById("detailLabels").style.display = "";
        document.getElementById("detail_contentTitle").style.display = "none";
        document.getElementById("detail_edit").style.display = "none";

        document.getElementById("detail_title").value = title;
        document.getElementById("detail_position").value = ext.position;
        document.getElementById("detail_moto").value = ext.moto;
        document.getElementById("detailuploadImg").src = imgUrl + imageUrl;
        document.getElementById("detail_priority").value = priority;
        document.getElementById("detailLabel").innerHTML = labelName
        document.getElementById("detail_edit").getElementsByClassName("fr-element")[0].innerHTML = content;

        document.getElementById("detailuploadImg").setAttribute("class", "uploadImg3");
    }
}

function delImg(obj,tp){
    var addType = document.getElementById("add_topTitle").innerHTML;
    var editType = document.getElementById("edit_topTitle").innerHTML;
    if(tp == 1){
        if(addType=="新增文章" || addType == "新增基本概况"){
            obj.parentElement.nextElementSibling.src = "images/articleAdd.png";
            document.getElementById("add_imgUrl").innerHTML = "images/articleAdd.png";
        }else if(addType == "新增图片"){
            obj.parentElement.nextElementSibling.src = "images/imageAdd.png";
            document.getElementById("add_imgUrl").innerHTML = "images/imageAdd.png";
        }else if(addType == "新增教师" || addType == "新增教师风采"){
            obj.parentElement.nextElementSibling.src = "images/teacherAdd.png";
            document.getElementById("add_imgUrl").innerHTML = "images/teacherAdd.png";
        }else if(addType == "新增学生"){
            obj.parentElement.nextElementSibling.src = "images/studentAdd.png";
            document.getElementById("add_imgUrl").innerHTML = "images/studentAdd.png";
        }
    }else if(tp == 2){
        if(editType == "修改文章" || editType == "修改基本概况"){
            obj.parentElement.nextElementSibling.src = "images/articleAdd.png";
            document.getElementById("edit_imgUrl").innerHTML = "images/articleAdd.png";
        }else if(editType == "修改图片"){
            obj.parentElement.nextElementSibling.src = "images/imageAdd.png";
            document.getElementById("edit_imgUrl").innerHTML = "images/imageAdd.png";
        }else if(editType == "修改教师" || editType == "修改教师风采"){
            obj.parentElement.nextElementSibling.src = "images/teacherAdd.png";
            document.getElementById("edit_imgUrl").innerHTML = "images/teacherAdd.png";
        }else if(editType == "修改学生"){
            obj.parentElement.nextElementSibling.src = "images/studentAdd.png";
            document.getElementById("edit_imgUrl").innerHTML = "images/studentAdd.png";
        }
    }

    var file = obj.parentElement.nextElementSibling.nextElementSibling;
    if (file.outerHTML) {
        file.outerHTML = file.outerHTML;
    } else { // FF(包括3.5)
        file.value = "";
    }
}

function selectColumn(){
    var addNowType = document.getElementById("add_topTitle").innerHTML;
    if(columnType == "编辑"){
        var columnType = document.getElementById("columnType").innerHTML;
        if(addNowType == "修改教师风采"){
            modalinfo("教师风采类型不可同步");
            return false;
        }
    }else if(columnType == "详情"){
        var articleType = document.getElementById("detail_type").innerHTML;
        if(articleType == "6"){
            modalinfo("教师风采类型不可同步");
            return false;
        }
    }
    showmodal("#columnmodal");
    selectTree();
}

function selectTree(){
    $.ajax({
        url : urladdr + "/web/menu/list",
        method : "GET",
        data : {
            token:Mytoken
        },
        success : function(data){
            if(data.code == 0){
                zNodes2.splice(0,zNodes2.length);
                $.each(data.data,function(i,date){
                    if(date.height == 0){
                        var d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", open:true, iconSkin:"pIcon01",type:date.type
                        };
                    }else if(date.height == 1){
                        d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", open:true, iconSkin:"icon01",type:date.type
                        };
                    }else if(date.height == 2){
                        d={
                            id:date.id, pId:date.parentId, name:date.title+"("+type[date.type]+")", iconSkin:"icon03",type:date.type
                        };
                    }
                    zNodes2.push(d);
                });
                setTimeout(function(){
                    $.fn.zTree.init($("#selectTree"), selectSetting, zNodes2);
                },100)
            }else if(data.code == 401){
                location.href = "login.html"
            }else{
                modalinfo(data.msg);
            }
        }
    });
}
